package com.link.base.core.basic.properties;

import com.link.base.core.basic.util.YmlConstants;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class YmlProperties implements InitializingBean {


    @Value("${application.uploadfile.portal.httpshare}")
    private String portalShareUrlDir;
    @Value(("${application.uploadfile.portal.share}"))
    private String portalShareFileDir;
    @Value("${application.io.temporary.httpshare}")
    private String temporaryIOUrlDir;
    @Value("${application.io.temporary.share}")
    private String temporaryIOFileDir;

    @Value("${application.database}")
    private String applicationDatabase;

    @Value("jdbc.mapperLocations")
    private String mapperLocations;

    /**
     * 微信相关参数
     */
    @Value(("${weixin.component.appid}"))
    private String componentAppId;
    @Value("${weixin.component.token}")
    private String componentToken;
    @Value("${weixin.component.aeskey}")
    private String componentAeskey;
    @Value("${weixin.component.appSecret}")
    private String componentAppSecret;
    @Value("${weixin.component.authRedirectUrl}")
    private String componentAuthRedirectUrl;
    @Value("${weixin.appId}")
    private String appId;
    @Value("${weixin.payCertPath}")
    private String payCertPath;

    @Value("${application.visitlog.env}")
    private String visitLogEnv;
    @Value("${application.tableSchema}")
    private String tableSchema;

    //dmstoken有效时间 秒为单位
    @Value("${dmp.keyexpires}")
    private Integer dmpKeyExpires;
    @Value("${dmp.ip}")
    private String dmpIp;

    /**SQL中是否拼接corpId，为Y时拼接，不为Y时不拼接*/
    @Value("${basicmodel.sqlandcorpid}")
    private String sqlAndCorpId;

    @Value("${spring.datasource.url}")
    private String datasourceUrl;

    @Value("${spring.datasource.username}")
    private String datasourceUsername;

    @Value("${spring.datasource.password}")
    private String datasourcePw;

    @Value("${application.updateoptions.updatespecifiedfields}")
    private String updatespecifiedfields;

    @Value("${baidu.mapKey}")
    private String mapKey;

    @Override
    public void afterPropertiesSet() throws Exception {

        YmlConstants.setPortalShareFileDir(portalShareFileDir);
        YmlConstants.setPortalShareUrlDir(portalShareUrlDir);
        YmlConstants.setTemporaryIOUrlDir(temporaryIOUrlDir);
        YmlConstants.setTemporaryIOFileDir(temporaryIOFileDir);
        YmlConstants.setApplicationDatabase(applicationDatabase);

        YmlConstants.setDmpKeyExpires(dmpKeyExpires);
        YmlConstants.setDmpIp(dmpIp);

        YmlConstants.setUpdateSpecifiedFields(updatespecifiedfields);
        String subString = "";
        // 用于判断后台是否走siebel数据库
        if (mapperLocations != null && !"".equals(mapperLocations) && mapperLocations.length() > 0) {
            subString = mapperLocations.substring(mapperLocations.length() - 10, mapperLocations.length());
        }
        String str = "Siebel.xml";
        if (str.equals(subString)) {
            YmlConstants.setDmsForSiebel("Y");
        } else {
            YmlConstants.setDmsForSiebel("N");
        }

        YmlConstants.setWxComponentAppId(componentAppId);
        YmlConstants.setWxComponentToken(componentToken);
        YmlConstants.setWxComponentAeskey(componentAeskey);
        YmlConstants.setWxComponentAppSecret(componentAppSecret);
        YmlConstants.setWxComponentAuthRedirectUrl(componentAuthRedirectUrl);
        YmlConstants.setWxAppId(appId);
        YmlConstants.setWxPayCertPath(payCertPath);
        YmlConstants.setVisitLogEnv(visitLogEnv);


        YmlConstants.setTableSchema(tableSchema);


        YmlConstants.setSqlAndCorpId(sqlAndCorpId);

        YmlConstants.setDatasourceUrl(datasourceUrl);
        YmlConstants.setDatasourceUsername(datasourceUsername);
        YmlConstants.setDatasourcePw(datasourcePw);

        YmlConstants.setBaiduMapKey(mapKey);
    }
}
